/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import controller.EditLab;
import controller.LabDetail;
import entities.Lab;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author QUY-THI
 */
@ManagedBean
@ViewScoped
public class LabDetailBean {

    private int labid;
    private String labname;
    private String description;
    private Lab lab;

    public int getLabid() {
        return labid;
    }

    public void setLabid(int labid) {
        this.labid = labid;
    }

    public String getLabname() {
        return labInfo().getLabname();
    }

    public void setLabname(String labname) {
        this.labname = labname;
    }

    public String getDescription() {
        return labInfo().getDescription();
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Lab getLab() {
        return labInfo();
    }

    public void setLab(Lab lab) {
        this.lab = lab;
    }

    /**
     * Creates a new instance of LabDetailBean
     */
    public LabDetailBean() {
    }

    public Lab labInfo() {
        LabDetail ld = new LabDetail();
        return ld.labDetail(labid);
    }

    public String editLab() {
        Lab lb = labInfo();
        lb.setLabname(labname);
        lb.setDescription(description);
        EditLab el = new EditLab();
        boolean resultEdit = el.resultEdit(lb);
        if (resultEdit) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "", "Action complete !"));
            return "";
        }
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Action error !"));
        return "";
    }
}
